<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx 动态配置更新指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .code-block {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 12px;
            padding: 1.5rem;
            margin: 1rem 0;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 0.5rem;
            right: 1rem;
            font-size: 0.75rem;
            color: #64748b;
            text-transform: uppercase;
        }
        
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            flex-shrink: 0;
        }
        
        .highlight-text {
            background: linear-gradient(to right, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
            margin: 3rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .fade-in-up {
            animation: fadeInUp 0.6s ease-out;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center fade-in-up">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-server mr-4"></i>Nginx 动态配置更新
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                掌握无缝配置更新技术，确保服务零中断运行
            </p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <div class="flex items-start space-x-4">
                <div class="text-4xl text-purple-600">
                    <i class="fas fa-lightbulb"></i>
                </div>
                <div class="flex-1">
                    <h2 class="text-2xl font-bold mb-4 text-gray-800">核心概念</h2>
                    <p class="text-lg text-gray-600 leading-relaxed">
                        Nginx 的动态配置更新功能通过平滑过渡机制确保服务的高可用性。通过编辑配置文件、测试配置和重新加载服务，可以在不中断服务的情况下应用新的配置。这使得 Nginx 成为处理高流量和复杂配置的可靠工具。
                    </p>
                </div>
            </div>
        </div>

        <!-- Process Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center text-gray-800">
                <i class="fas fa-sync-alt mr-3 text-purple-600"></i>配置更新流程
            </h2>
            <div class="mermaid">
                graph LR
                    A[编辑配置文件] --> B[测试配置 nginx -t]
                    B --> C{配置有效?}
                    C -->|是| D[重新加载 nginx -s reload]
                    C -->|否| E[修复错误]
                    E --> A
                    D --> F[新配置生效]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Steps Grid -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <!-- Step 1 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start space-x-4 mb-6">
                    <div class="step-number">1</div>
                    <h3 class="text-2xl font-bold text-gray-800">配置文件的编辑</h3>
                </div>
                <p class="text-gray-600 leading-relaxed mb-4">
                    在 Nginx 中，动态配置更新主要通过编辑配置文件来实现。配置文件通常位于：
                </p>
                <div class="bg-gray-100 rounded-lg p-4 font-mono text-sm">
                    <p><i class="fas fa-folder mr-2 text-purple-600"></i>/etc/nginx/nginx.conf</p>
                    <p><i class="fas fa-folder mr-2 text-purple-600"></i>/etc/nginx/conf.d/</p>
                </div>
            </div>

            <!-- Step 2 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start space-x-4 mb-6">
                    <div class="step-number">2</div>
                    <h3 class="text-2xl font-bold text-gray-800">测试配置文件</h3>
                </div>
                <p class="text-gray-600 leading-relaxed mb-4">
                    在进行配置更改后，首先要确保新配置是有效的：
                </p>
                <div class="code-block" data-lang="bash">
                    <code>sudo nginx -t</code>
                </div>
                <p class="text-sm text-gray-500 mt-4">
                    <i class="fas fa-check-circle mr-2 text-green-500"></i>
                    成功时显示：syntax is ok & test is successful
                </p>
            </div>

            <!-- Step 3 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start space-x-4 mb-6">
                    <div class="step-number">3</div>
                    <h3 class="text-2xl font-bold text-gray-800">重新加载配置</h3>
                </div>
                <p class="text-gray-600 leading-relaxed mb-4">
                    配置文件测试通过后，重新加载 Nginx 配置：
                </p>
                <div class="code-block" data-lang="bash">
                    <code>sudo systemctl reload nginx</code>
                </div>
                <p class="text-center text-gray-500 my-2">或</p>
                <div class="code-block" data-lang="bash">
                    <code>sudo nginx -s reload</code>
                </div>
            </div>

            <!-- Step 4 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start space-x-4 mb-6">
                    <div class="step-number">4</div>
                    <h3 class="text-2xl font-bold text-gray-800">工作原理</h3>
                </div>
                <div class="space-y-3">
                    <div class="flex items-start space-x-3">
                        <i class="fas fa-signal text-purple-600 mt-1"></i>
                        <p class="text-gray-600">旧进程接收 SIGHUP 信号</p>
                    </div>
                    <div class="flex items-start space-x-3">
                        <i class="fas fa-cog text-purple-600 mt-1"></i>
                        <p class="text-gray-600">新进程加载新配置</p>
                    </div>
                    <div class="flex items-start space-x-3">
                        <i class="fas fa-exchange-alt text-purple-600 mt-1"></i>
                        <p class="text-gray-600">优雅地平滑过渡</p>
                    </div>
                    <div class="flex items-start space-x-3">
                        <i class="fas fa-power-off text-purple-600 mt-1"></i>
                        <p class="text-gray-600">旧进程退出</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Example Section -->
        <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-code mr-3 text-purple-600"></i>实战示例
            </h2>
            <p class="text-lg text-gray-600 mb-6">
                假设我们要更新 Nginx 的负载均衡配置，将一个新的后端服务器添加到 upstream 块中：
            </p>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div>
                    <h4 class="font-bold text-gray-700 mb-3">
                        <i class="fas fa-file-alt mr-2"></i>原配置
                    </h4>
                    <div class="code-block" data-lang="nginx">
                        <code>upstream backend {
    server backend1.toString.com;
    server backend2.toString.com;
}</code>
                    </div>
                </div>
                
                <div>
                    <h4 class="font-bold text-gray-700 mb-3">
                        <i class="fas fa-file-alt mr-2"></i>更新配置
                    </h4>
                    <div class="code-block" data-lang="nginx">
                        <code>upstream backend {
    server backend1.toString.com;
    server backend2.toString.com;
    <span class="text-green-400">server backend3.toString.com;  # 新增的服务器</span>
}</code>
                    </div>
                </div>
            </div>
        </div>

        <!-- Hot Update Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-fire mr-3 text-orange-500"></i>配置热更新
            </h2>
            <p class="text-lg text-gray-600 leading-relaxed">
                某些高级配置可以通过特定的模块或 Nginx 的扩展来支持热更新。例如，<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">ngx_http_upstream_module</code> 可以配置为支持热更新，以便在不中断服务的情况下更新上游服务器列表。
            </p>
        </div>

        <!-- Important Notes -->
        <div class="bg-gradient-to-r from-yellow-50 to-orange-50 rounded-2xl p-8">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-exclamation-triangle mr-3 text-yellow-600"></i>注意事项
            </h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl p-6 shadow-md">
                    <div class="text-3xl text-yellow-600 mb-4 text-center">
                        <i class="fas fa-check-double"></i>
                    </div>
                    <h4 class="font-bold text-gray-700 mb-2">确保配置正确</h4>
                    <p class="text-gray-600 text-sm">
                        在重新加载配置之前，总是测试配置文件的正确性，以避免引发服务中断。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl p-6 shadow-md">
                    <div class="text-3xl text-yellow-600 mb-4 text-center">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <h4 class="font-bold text-gray-700